package cn.wolfcode.edu.service.impl;

import cn.wolfcode.edu.domain.BigCustomer;
import cn.wolfcode.edu.domain.SchoolContact;
import cn.wolfcode.edu.mapper.SchoolContactMapper;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.ISchoolContactService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by NEUZJ on 2018/7/8.
 */
@Service
public class SchoolContactServiceImpl implements ISchoolContactService {
    @Autowired
    private SchoolContactMapper schoolContactMapper;
    @Override
    public void save(SchoolContact schoolcontact) {
        //获得学校联系人所在学校的id,通过这个id.进行更改操作
        Long id=schoolcontact.getSchool().getId();
        System.out.print(id);
        schoolContactMapper.updatePrincipleById(id,SchoolContact.UNNORMAL_PRINCIPAL,SchoolContact.NORMAL_PRINCIPAL);
        System.out.print(schoolcontact);
        schoolContactMapper.insert(schoolcontact);
    }

    @Override
    public PageResult query(QueryObject qo) {
        int  total=schoolContactMapper.queryForCount(qo);
        if(total==0){
            return new PageResult();
        }
        List list=schoolContactMapper.queryForList(qo);
        return new PageResult(total,list);
    }

    @Override
    public void update(SchoolContact schoolcontact) {
        schoolContactMapper.updateByPrimaryKey(schoolcontact);
    }

    @Override
    public void delete(Long id) {
        schoolContactMapper.fireSchoolContactById(id);
    }

    @Override
    public List<BigCustomer> listAllBigCustomer() {
        return schoolContactMapper.listAllBigCustomer();
    }
}
